package com.quanxiaoha.weblog.admin.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quanxiaoha.weblog.admin.model.vo.blogSetting.FindBlogSettingsRspVO;
import com.quanxiaoha.weblog.admin.model.vo.blogSetting.UpdateBlogSettingsReqVO;
import com.quanxiaoha.weblog.admin.service.AdminBlogSettingService;
import com.quanxiaoha.weblog.admin.service.AdminFileService;
import com.quanxiaoha.weblog.common.domain.dos.BlogSettingsDO;
import com.quanxiaoha.weblog.common.domain.mapper.BlogSettingsMapper;

import com.quanxiaoha.weblog.common.utils.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class AdminBlogSettingServiceImpl extends ServiceImpl<BlogSettingsMapper, BlogSettingsDO> implements AdminBlogSettingService {

    @Autowired
    private BlogSettingsMapper blogSettingsMapper;


    /**
     * 更新博客设置
     *
     * @param updateBlogSettingsReqVO
     * @return
     */
    public Response updateSettings(UpdateBlogSettingsReqVO updateBlogSettingsReqVO) {
        BlogSettingsDO blogSettingsDO = new BlogSettingsDO();
        BeanUtils.copyProperties(updateBlogSettingsReqVO, blogSettingsDO);
        blogSettingsDO.setId(1L);
//        saveOrUpdate(blogSettingsDO);
        boolean b = update(blogSettingsDO, null);
        return Response.success(b);
    }

    /**
     * 根据id查看博客设置
     *
     * @param id
     * @return
     */
    @Override
    public Response getDetail(Long id) {
        BlogSettingsDO blogSettingDO = getById(id);
        //do转vo
        FindBlogSettingsRspVO findBlogSettingsRspVO = new FindBlogSettingsRspVO();
        BeanUtils.copyProperties(blogSettingDO, findBlogSettingsRspVO);
        //响应
        return Response.success(findBlogSettingsRspVO);
    }
}
